package org.spring.springboot.app.adv.advarea.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spring.springboot.app.adv.advarea.dao.AdvAreaDao;
import org.spring.springboot.app.adv.advarea.domain.po.AdvAreaPO;
import org.spring.springboot.app.adv.advarea.service.IAdvAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdvAreaServiceImpl implements IAdvAreaService {
    private static final Logger LOGGER = LoggerFactory.getLogger(AdvAreaServiceImpl.class);

    @Autowired
    private AdvAreaDao advAreaDao;


    @Override
    public int insert(AdvAreaPO areaPO) {
        return advAreaDao.insertSelective(areaPO);
    }

    @Override
    public int deleteByAdvId(String id) {
        return advAreaDao.deleteByAdvId(id);
    }

    @Override
    public List<AdvAreaPO> queryAreaList(String advId) {
        return advAreaDao.queryListByAdvId(advId);
    }

    @Override
    public int saveAreas(String advId, String areaIds) {
        String[] arr = areaIds.split(",");
        for (String areaId : arr){
            AdvAreaPO areaPO = new AdvAreaPO();
            areaPO.setAdvId(advId);
            areaPO.setAreaId(areaId);
            advAreaDao.insertSelective(areaPO);
        }
        return 1;
    }
}
